package com.ysy.tz.mfg.component;

import com.ysy.tz.core.engine.ApplicationContext;
import com.ysy.tz.core.engine.CustomerFXMLLoader;
import com.ysy.tz.core.utils.FileResourceLoader;
import java.io.IOException;
import java.math.BigDecimal;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Effect;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import org.apache.commons.lang3.StringUtils;

public class PigGradingOldNode extends StackPane {
    private BooleanProperty normalProperty = new SimpleBooleanProperty(true);
    private StringProperty actionProperty = new SimpleStringProperty("");
    private BooleanProperty choiseProperty = new SimpleBooleanProperty(false);
    private IntegerProperty todayStartNumber = new SimpleIntegerProperty();
    private IntegerProperty numberPerOrder = new SimpleIntegerProperty();
    @FXML
    private BorderPane pigGradingBackPane;
    @FXML
    private Region topBorder;
    @FXML
    private Region leftBorder;
    @FXML
    private Region bottomBorder;
    @FXML
    private Region rightBorder;
    @FXML
    private FlowPane titleImgPane;
    @FXML
    private ImageView pigGradingTitleImg;
    private static Image titleImg;
    @FXML
    private Label statusLabel;
    @FXML
    private BorderPane pigGradingInfoPane;
    private boolean empty = false;
    private static Image topImg;
    private ImageView choiseTopImg;
    private String currentColor = "-fx-background-color:rgb(206,251,234)";
    private DropShadow shadow;
    @FXML
    private PigGradingLabel fatLabel;
    private ObjectProperty<BigDecimal> fatProperty;
    @FXML
    private PigGradingLabel leanMeatLabel;
    private ObjectProperty<BigDecimal> leanMeatProperty;
    @FXML
    private PigGradingLabel weightLabel;
    private ObjectProperty<BigDecimal> weightProperty;
    @FXML
    private PigGradingLabel gradingLabel;
    private StringProperty gradingProperty;
    @FXML
    private PigGradingLabel slaughterNumberLabel;
    private StringProperty slaughterNumberProperty;
    private Button emptyButton;

    public PigGradingOldNode() {
        this.shadow = new DropShadow(5.0, 0.0, 0.0, Color.LIGHTGRAY);
        this.fatProperty = new SimpleObjectProperty();
        this.leanMeatProperty = new SimpleObjectProperty();
        this.weightProperty = new SimpleObjectProperty();
        this.gradingProperty = new SimpleStringProperty();
        this.slaughterNumberProperty = new SimpleStringProperty();
        if (titleImg == null) {
            try {
                titleImg = new Image(FileResourceLoader.loadInputStream("/views/images/pigGradingTitle.png"));
                topImg = new Image(FileResourceLoader.loadInputStream("/views/images/pigGradingChoise.png"));
            } catch (IOException var4) {
                var4.printStackTrace();
            }
        }

        CustomerFXMLLoader loader = new CustomerFXMLLoader();

        try {
            loader.setRoot(this);
            loader.setController(this);
            loader.setResources(ApplicationContext.commonBundle);
            loader.load(FileResourceLoader.loadInputStream("/views/PigGradingNodeView.fxml"));
        } catch (IOException var3) {
            throw new RuntimeException(var3);
        }

        this.changeBorderColor("-fx-background-color:rgb(206,251,234)");
        this.pigGradingTitleImg.setOpacity(0.3);
        this.pigGradingTitleImg.setImage(titleImg);
        this.statusLabel.setStyle("-fx-background-color:rgb(235,241,255); -fx-font-size: 16px;");
        this.statusLabel.setAlignment(Pos.CENTER);
        this.statusLabel.setVisible(false);
        this.titleImgPane.setStyle("-fx-padding: 10 0 0 15;");
        this.slaughterNumberLabel.setValue(new String[]{"20221202", "T 999"});
        this.normalProperty.addListener((observable, oldValue, newValue) -> {
            if (newValue) {
                this.currentColor = "-fx-background-color:rgb(206,251,234)";
            } else {
                this.currentColor = "-fx-background-color:rgb(255,239,230)";
            }

            this.changeBorderColor(this.currentColor);
        });
        this.actionProperty.addListener((observable, oldValue, newValue) -> {
            if (StringUtils.isNotBlank(newValue)) {
                this.statusLabel.setText(newValue);
                this.statusLabel.setVisible(true);
            } else {
                this.statusLabel.setVisible(false);
            }

        });
        this.choiseProperty.addListener((observable, oldValue, newValue) -> {
            this.selectAllLabel(newValue);
            if (newValue) {
                if (this.choiseTopImg == null) {
                    this.choiseTopImg = new ImageView(topImg);
                    this.choiseTopImg.fitWidthProperty().bind(this.pigGradingBackPane.widthProperty());
                    this.choiseTopImg.setFitHeight(25.0);
                }

                this.pigGradingTitleImg.setOpacity(0.1);
                this.titleImgPane.setStyle("-fx-padding: 10 0 0 0;");
                this.titleImgPane.setAlignment(Pos.CENTER);
                this.pigGradingBackPane.setTop(this.choiseTopImg);
                this.pigGradingBackPane.setEffect(this.shadow);
                this.statusLabel.setEffect(this.shadow);
                this.changeBorderColor("-fx-background-color:rgb(255,214,214)");
            } else {
                this.titleImgPane.setStyle("-fx-padding: 10 0 0 15;");
                this.titleImgPane.setAlignment(Pos.CENTER_LEFT);
                this.pigGradingTitleImg.setOpacity(0.3);
                this.pigGradingBackPane.setEffect((Effect)null);
                this.pigGradingBackPane.setTop(this.topBorder);
                this.statusLabel.setEffect((Effect)null);
                this.changeBorderColor(this.currentColor);
            }

        });
        this.fatProperty.addListener((observable, oldValue, newValue) -> {
            this.fatLabel.setValue(new String[]{newValue.toString()});
        });
        this.leanMeatProperty.addListener((observable, oldValue, newValue) -> {
            this.leanMeatLabel.setValue(new String[]{newValue.toString()});
        });
        this.weightProperty.addListener((observable, oldValue, newValue) -> {
            this.weightLabel.setValue(new String[]{newValue.toString()});
        });
        this.gradingProperty.addListener((observable, oldValue, newValue) -> {
            this.gradingLabel.setValue(new String[]{newValue.toString()});
        });
        this.setOnMousePressed((mouseEvent) -> {
            if (!this.empty) {
                ;
            }
        });
    }

    private void changeBorderColor(String color) {
        this.topBorder.setStyle(color);
        this.leftBorder.setStyle(color);
        this.rightBorder.setStyle(color);
        this.bottomBorder.setStyle(color);
    }

    private void selectAllLabel(boolean select) {
        this.fatLabel.select(select);
        this.leanMeatLabel.select(select);
        this.weightLabel.select(select);
        this.gradingLabel.select(select);
        this.slaughterNumberLabel.select(select);
    }

    public boolean isNormalProperty() {
        return this.normalProperty.get();
    }

    public BooleanProperty normalPropertyProperty() {
        return this.normalProperty;
    }

    public void setNormalProperty(boolean normalProperty) {
        this.normalProperty.set(normalProperty);
    }

    public String getActionProperty() {
        return (String)this.actionProperty.get();
    }

    public StringProperty actionPropertyProperty() {
        return this.actionProperty;
    }

    public void setActionProperty(String actionProperty) {
        this.actionProperty.set(actionProperty);
    }

    public boolean isChoiseProperty() {
        return this.choiseProperty.get();
    }

    public BooleanProperty choisePropertyProperty() {
        return this.choiseProperty;
    }

    public void setChoiseProperty(boolean choiseProperty) {
        this.choiseProperty.set(choiseProperty);
    }

    public int getTodayStartNumber() {
        return this.todayStartNumber.get();
    }

    public IntegerProperty todayStartNumberProperty() {
        return this.todayStartNumber;
    }

    public void setTodayStartNumber(int todayStartNumber) {
        this.todayStartNumber.set(todayStartNumber);
    }

    public int getNumberPerOrder() {
        return this.numberPerOrder.get();
    }

    public IntegerProperty numberPerOrderProperty() {
        return this.numberPerOrder;
    }

    public void setNumberPerOrder(int numberPerOrder) {
        this.numberPerOrder.set(numberPerOrder);
    }

    public BorderPane getPigGradingBackPane() {
        return this.pigGradingBackPane;
    }

    public void setPigGradingBackPane(BorderPane pigGradingBackPane) {
        this.pigGradingBackPane = pigGradingBackPane;
    }

    public BigDecimal getFatProperty() {
        return (BigDecimal)this.fatProperty.get();
    }

    public ObjectProperty<BigDecimal> fatPropertyProperty() {
        return this.fatProperty;
    }

    public void setFatProperty(BigDecimal fatProperty) {
        this.fatProperty.set(fatProperty);
    }

    public BigDecimal getLeanMeatProperty() {
        return (BigDecimal)this.leanMeatProperty.get();
    }

    public ObjectProperty<BigDecimal> leanMeatPropertyProperty() {
        return this.leanMeatProperty;
    }

    public void setLeanMeatProperty(BigDecimal leanMeatProperty) {
        this.leanMeatProperty.set(leanMeatProperty);
    }

    public BigDecimal getWeightProperty() {
        return (BigDecimal)this.weightProperty.get();
    }

    public ObjectProperty<BigDecimal> weightPropertyProperty() {
        return this.weightProperty;
    }

    public void setWeightProperty(BigDecimal weightProperty) {
        this.weightProperty.set(weightProperty);
    }

    public String getGradingProperty() {
        return (String)this.gradingProperty.get();
    }

    public StringProperty gradingPropertyProperty() {
        return this.gradingProperty;
    }

    public void setGradingProperty(String gradingProperty) {
        this.gradingProperty.set(gradingProperty);
    }

    public String getSlaughterNumberProperty() {
        return (String)this.slaughterNumberProperty.get();
    }

    public StringProperty slaughterNumberPropertyProperty() {
        return this.slaughterNumberProperty;
    }

    public void setSlaughterNumberProperty(String slaughterNumberProperty) {
        this.slaughterNumberProperty.set(slaughterNumberProperty);
    }

    public boolean isEmpty() {
        return this.empty;
    }

    public void setEmpty(boolean empty) {
        if (!empty) {
            throw new IllegalArgumentException("empty only can set true!");
        } else {
            this.empty = empty;
            if (this.emptyButton == null) {
                this.emptyButton = new Button("empty");
                this.emptyButton.prefWidthProperty().bind(this.pigGradingBackPane.widthProperty());
                this.emptyButton.prefHeightProperty().bind(this.pigGradingBackPane.heightProperty());
            }

            this.pigGradingInfoPane.getChildren().clear();
            this.titleImgPane.getChildren().clear();
            this.pigGradingBackPane.setTop((Node)null);
            this.pigGradingBackPane.setLeft((Node)null);
            this.pigGradingBackPane.setRight((Node)null);
            this.pigGradingBackPane.setBottom((Node)null);
            this.pigGradingBackPane.setCenter(this.emptyButton);
        }
    }
}
